import re
from typing import Dict


class Soldier(Dict):
    def __init__(self, info_str) -> None:
        self.info = info_str
        self["兵种名称"] = self.__match(r"(?<=\|)兵种名称=(.*?)(?=\n)")
        self["兵种类型"] = self.__match(r"(?<=\|)兵种类型=(.*?)(?=\n)")
        self["兵种等级"] = self.__match(r"(?<=\|)兵种等级=(.*?)(?=\n)")
        self["射程"] = self.__match(r"(?<=\|)射程=(.*?)(?=\n)")
        self["移动"] = self.__match(r"(?<=\|)移动=(.*?)(?=\n)")
        self["克制"] = self.__match(r"(?<=\|)克制=(.*?)(?=\n)")
        self["弱点"] = self.__match(r"(?<=\|)弱点=(.*?)(?=\n)")
        self["生命"] = self.__match(r"(?<=\|)生命=(.*?)(?=\n)")
        self["攻击"] = self.__match(r"(?<=\|)攻击=(.*?)(?=\n)")
        self["防御"] = self.__match(r"(?<=\|)防御=(.*?)(?=\n)")
        self["魔防"] = self.__match(r"(?<=\|)魔防=(.*?)(?=\n)")
        self["生命MAX"] = self.__match(r"(?<=\|)生命MAX=(.*?)(?=\n)")
        self["攻击MAX"] = self.__match(r"(?<=\|)攻击MAX=(.*?)(?=\n)")
        self["防御MAX"] = self.__match(r"(?<=\|)防御MAX=(.*?)(?=\n)")
        self["魔防MAX"] = self.__match(r"(?<=\|)魔防MAX=(.*?)(?=\n)")
        self["初始技能"] = self.__match(r"\|初始技能=(.*\n){1,}?\|").replace("\n", "")
        self["满级技能"] = self.__match(r"\|满级技能=(.*\n){1,}?\|").replace("\n", "")

    def __match(self, format):
        value = re.search(format, self.info, re.MULTILINE)
        return value.group(1) if value else ""
